home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrMultiSet<T,C> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tpmset.h> RWTPtrMultiSet<T,C> s; SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy DDDDeeeeppppeeeennnnddddeeeennnntttt!!!! RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt requires the Standard C++ Library. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a pointer-based collection of values, which are ordered according to a comparison object of type CCCC. Class TTTT is the type pointed to by the items in the collection. CCCC must induce a total ordering on elements of type TTTT via a public member bool operator()(const T& x, const T& y) which returns ttttrrrruuuueeee if xxxx should precede yyyy within the collection. The structure lllleeeessssssss<<<<TTTT>>>> from the C++-standard header file <<<<ffffuuuunnnnccccttttiiiioooonnnnaaaallll>>>> is an example. Note that items in the collection will be dereferenced before being compared. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> may contain multiple items that compare equal to each other. (RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> will not accept an item that compares equal to an item already in the collection.) PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic. EEEExxxxaaaammmmpppplllleeeessss In this example, a multi-set of RRRRWWWWCCCCSSSSttttrrrriiiinnnnggggs is exercised. // // tpmset.cpp // #include <rw/tpmset.h> #include <rw/cstring.h> #include <iostream.h> #include <function.h> PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) main(){ RWTPtrMultiSet<RWCString, less<RWCString> > set; set.insert(new RWCString("one")); set.insert(new RWCString("two")); set.insert(new RWCString("three")); set.insert(new RWCString("one")); // OK: duplicates allowd cout << set.entries() << endl; // Prints "4" set.clearAndDestroy(); cout << set.entries() << endl; // Prints "0" return 0; RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss } Class RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> offers the same interface to a pointer-based collection that will not accept multiple items that compare equal to each other. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> maintains is a pointer-based collection of key-value pairs. Class mmmmuuuullllttttiiiisssseeeetttt<<<<TTTT****,,,, rrrrwwww____ddddeeeerrrreeeeffff____ccccoooommmmppppaaaarrrreeee<<<<CCCC,,,,TTTT>>>>,,,,aaaallllllllooooccccaaaattttoooorrrr >>>> is the C++-standard collection that serves as the underlying implementation for RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss typedef rw_deref_compare<C,T> container_comp; typedef multiset<T*, container_comp,allocator> container_type; typedef container_type::size_type size_type; typedef container_type::difference_type difference_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef T* value_type; typedef T* const& reference; typedef T* const& const_reference; PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const container_comp& = container_comp()); Constructs an empty set. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const RWTPtrMultiSet<T,C>& rws); Copy constructor. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const container_type>& ms); Constructs a multimap by copying all elements from mmmmssss. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(T* const* first,T* const* last,const container_comp& = container_comp()); Constructs a set by copying elements from the array of TTTT****s pointed to by ffffiiiirrrrsssstttt, up to, but not including, the element pointed to by llllaaaasssstttt. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrMultiSet<T,C>& ooooppppeeeerrrraaaattttoooorrrr====(const container_type>& s); RWTPtrMultiSet<T,C>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrMultiSet<T,C>& s); Clears all elements of self and replaces them by copying all elements of ssss. bool ooooppppeeeerrrraaaattttoooorrrr<<<<(const RWTPtrMultiSet<T,C>& s) const; Returns ttttrrrruuuueeee if self compares lexicographically less than ssss, otherwise returns ffffaaaallllsssseeee. Items in each collection are dereferenced before being compared. Assumes that type TTTT has well-defined less-than semantics. bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTPtrMultiSet<T,C>& s) const; Returns ttttrrrruuuueeee if self compares equal to ssss, otherwise returns ffffaaaallllsssseeee. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other. Elements are dereferenced before being PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) compared. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const T*,void*), void* d) const; Applies the user-defined function pointed to by ffffnnnn to every item in the collection. This function must have prototype: void yourfun(const T* a, void* d); Client data may be passed through parameter dddd. iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; Returns an iterator positioned at the first element of self. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all items from the collection and uses ooooppppeeeerrrraaaattttoooorrrr ddddeeeelllleeeetttteeee to destroy the objects pointed to by those items. Do not use this method if multiple pointers to the same object are stored. bool ccccoooonnnnttttaaaaiiiinnnnssss(const T* a) const; Returns ttttrrrruuuueeee if there exists an element tttt in self that compares equal to ****aaaa, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(const T*,void*), void* d) const; Returns ttttrrrruuuueeee if there exists an element tttt in self such that the PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const T* a, void* d); Client data may be passed through parameter dddd. void ddddiiiiffffffffeeeerrrreeeennnncccceeee(const RWTPtrMultiSet<T,C>& s); Sets self to the set-theoretic difference given by ((((sssseeeellllffff ---- ssss)))). Elements from each set are dereferenced before being compared. iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last element in self. size_type eeeennnnttttrrrriiiieeeessss(); Returns the number of items in self. const T* ffffiiiinnnndddd(const T* a) const; If there exists an element tttt in self such that the expression ((((****tttt ======== ****aaaa)))) is ttttrrrruuuueeee, returns tttt. Otherwise, returns rrrrwwwwnnnniiiillll. const T* ffffiiiinnnndddd(bool (*fn)(T*,void*), void* d); const T* ffffiiiinnnndddd(bool (*fn)(const T*,void*), void* d) const; If there exists an element tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, returns tttt. Otherwise, returns rrrrwwwwnnnniiiillll. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const T* a, void* d); PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) Client data may be passed through parameter dddd. bool iiiinnnnsssseeeerrrrtttt(T* a); Adds the item aaaa to the collection. Returns ttttrrrruuuueeee. void iiiinnnntttteeeerrrrsssseeeeccccttttiiiioooonnnn(const RWTPtrMultiSet<T,C>& s); Sets self to the intersection of self and ssss. Elements from each set are dereferenced before being compared. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. bool iiiissssEEEEqqqquuuuiiiivvvvaaaalllleeeennnntttt(const RWTPtrMultiSet<T,C>& s) const; Returns ttttrrrruuuueeee if there is set equivalence between self and ssss, and returns ffffaaaallllsssseeee otherwise. bool iiiissssPPPPrrrrooooppppeeeerrrrSSSSuuuubbbbsssseeeettttOOOOffff(const RWTPtrMultiSet<T,C>& s) const; Returns ttttrrrruuuueeee if self is a proper subset of ssss, and returns ffffaaaallllsssseeee otherwise. bool iiiissssSSSSuuuubbbbsssseeeettttOOOOffff(const RWTPtrMultiSet<T,C>& s) const; Returns ttttrrrruuuueeee if self is a subset of ssss or if self is set equivalent to rrrrhhhhssss, ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T* a) const; Returns the number of elements tttt in self that compare equal to ****aaaa. PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(bool (*fn)(const T*,void*), void* d) const; Returns the number of elements tttt in self such that the expression((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const T* a, void* d); Client data may be passed through parameter dddd. T* rrrreeeemmmmoooovvvveeee(const T* a); Removes and returns the first element tttt in self that compares equal to ****aaaa. Returns rrrrwwwwnnnniiiillll if there is no such element. T* rrrreeeemmmmoooovvvveeee(bool (*fn)(const T*,void*), void* d); Removes and returns the first element tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee. Returns rrrrwwwwnnnniiiillll if there is no such element. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const T* a, void* d); Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T* a); Removes all elements tttt in self that compare equal to ****aaaa. Returns the number of items removed. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(const T*,void*), void* d); Removes all elements tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number of items removed. ffffnnnn points to a user-defined PPPPaaaaggggeeee 7777 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) tester function which must have prototype: bool yourTester(const T* a, void* d); Client data may be passed through parameter dddd. multiset<T*, container_comp,allocator>& ssssttttdddd(); const multiset<T*, container_comp,allocator>& ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves as the implementation for self. void ssssyyyymmmmmmmmeeeettttrrrriiiiccccDDDDiiiiffffffffeeeerrrreeeennnncccceeee(const RWTPtrMultiSet<T,C>& s); Sets self to the symmetric difference of self and ssss. Elements from each set are dereferenced before being compared. void UUUUnnnniiiioooonnnn(const RWTPtrMultiSet<T,C>& s); Sets self to the union of self and ssss. Elements from each set are dereferenced before being compared. Note the uppercase "U" in UUUUnnnniiiioooonnnn to avoid conflict with the C++ reserved word. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrMultiSet<T,C>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrMultiSet<T,C>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrMultiSet<T,C>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrMultiSet<T,C>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrMultiSet<T,C>*& p); RWFile& PPPPaaaaggggeeee 8888 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrMultiSet<T,C>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 9999